#include "trap.h"
#include "inst_test.h"
#include "asm/regdef.h"
#include "asm/asm.h"
    .set noreorder
    .set noat 
    .global main 
    .text 

main:
    # 初始化
    ori $t0, $zero, 10          # $t0 = 10
    ori $t1, $zero, 20          # $t1 = 20
    ori $t2, $zero, 0xFF        # $t2 = 0xFF

    # 分支指令与延迟槽
    beq $t0, $t1, skip2         # 如果$t0 == $t1，跳转到skip2
    addiu $t3, $zero, 1         # 延迟槽：$t3 = 1 (应执行)
    ori $t4, $zero, 0x1234      # 不应执行
skip2:
    addu $t5, $t0, $t1          # $t5 = $t0 + $t1

    # 跳转指令与延迟槽
    j end2                      # 无条件跳转到end2
    xor $t6, $t5, $t2           # 延迟槽：$t6 = $t5 ^ $t2
    ori $t7, $zero, 0x0         # 不应执行
end2:
    add $t8, $t6, $t0           # $t8 = $t6 + $t0

    # 延迟槽与循环
    ori $s0, $zero, 3           # $s0 = 3
loop2:
    beq $s0, $zero, endloop2    # 如果$s0 == 0，跳出循环
    add $t9, $s0, $t8           # 延迟槽：$t9 = $s0 + $t8
    sub $s0, $s0, 1             # $s0 -= 1
    j loop2                     # 跳回loop2
endloop2:
    nop

    HIT_GOOD_TRAP

inst_error:
    HIT_BAD_TRAP